// pages/reconciliationDetails/reconciliationDetails.js
let app = getApp();
import { getCarOrderListApi } from "../../api/index.js";
Page({
  /**
   * 页面的初始数据
   */
  data: {
    pageAllHeight: app.globalData.pageAllHeight - 200,
    stopCarList: [],
    parkId: null,
    parkName: "",
    pageNum: 1,
    pageSize: 5,
    totalCount: 0,
    pageFlag: false,
    keyWord: "",
    carNumber: null,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    console.log(options);
    if(options.parkId) {
        this.setData({
            parkId:options.parkId
        })
        // this.getOrderDetail()
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {},

  //   获取搜索值
  getCarNumberValue(e) {
    this.setData({
      carNumber: e.detail,
    });
    this.getOrderDetail();
  },

  //   车费明细
  async getOrderDetail(next) {
    const { parkId, pageNum, pageSize, stopCarList, carNumber } = this.data;
    const { data: res } = await getCarOrderListApi({
      parkId,
      carNumber,
      pageNum,
      pageSize,
    });
    const newStopCarList = next
      ? stopCarList.concat(res.data.records)
      : res.data.records;
    this.setData({
      stopCarList: newStopCarList,
      pageFlag: !res.data.records.length && next,
    });
  },

  // 触底事件函数
  scrollToLower() {
    const { pageFlag,stopCarList } = this.data;
    if (stopCarList.length === 0) {
      return;
    }
    if (!pageFlag) {
      this.setData({ pageNum: this.data.pageNum + 1 });
      this.getOrderDetail(true);
    }
  },
});
